//
//  HMToolbarView.swift
//  Weibo
//
//  Created by ZhuDong on 16/5/25.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

let sepWidth = 1.0 / UIScreen.mainScreen().scale
class HMToolbarView: UIView {
    var statusViewModel: HMStatusViewModel?{
        didSet{
            
            repostBtn.setTitle(statusViewModel?.reposts_text, forState: .Normal)
            commentBtn.setTitle(statusViewModel?.comments_text, forState: .Normal)
            agreeBtn.setTitle(statusViewModel?.attitudes_text, forState: .Normal)
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.greenColor()
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        addBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet", titleColor: UIColor.darkGrayColor())
        addBtn(commentBtn, title: "评论", imageName: "timeline_icon_comment", titleColor: UIColor.darkGrayColor())
        addBtn(agreeBtn, title: "赞", imageName: "timeline_icon_like", titleColor: UIColor.darkGrayColor())
        repostBtn.snp_makeConstraints { (make) in
            make.left.equalTo(self)
            make.centerY.equalTo(self)
        }
        commentBtn.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            make.top.equalTo(repostBtn.snp_top)
            make.width.equalTo(repostBtn)
        }
        agreeBtn.snp_makeConstraints { (make) in
            make.top.equalTo(commentBtn)
            make.left.equalTo(commentBtn.snp_right)
            make.right.equalTo(self)
            make.width.equalTo(repostBtn)
        }
        
        let sep1 = sepView()
        let sep2 = sepView()
        addSubview(sep1)
        addSubview(sep2)
        
        sep1.snp_makeConstraints { (make) in
            make.centerX.equalTo(repostBtn.snp_right)
            make.width.equalTo(sepWidth)
            make.centerY.equalTo(repostBtn)
            make.height.equalTo(20)
        }
        
        sep2.snp_makeConstraints { (make) in
            make.centerX.equalTo(agreeBtn.snp_left)
            make.width.equalTo(sepWidth)
            make.centerY.equalTo(repostBtn)
            make.height.equalTo(20)
        }
        
    }
    private func sepView() -> UIView{
        let v = UIView()
        v.backgroundColor = UIColor.darkGrayColor()
        return v
    }
    private func addBtn(btn: UIButton, title: String,imageName: String,titleColor: UIColor){
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(titleColor, forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.sizeToFit()
        self.addSubview(btn)
    }
    lazy var repostBtn = UIButton()
    lazy var commentBtn = UIButton()
    lazy var agreeBtn = UIButton()
}
